// $Id: loggercount.cpp 36 2004-09-22 19:02:54Z hansemil $
#include "loggercount.h"
#include <algorithm>
using namespace std;

/**
 * This method writes statisticly meaningful information about a vector of integers to a fstream.
 * The provided data is
 * - Average
 * - Minimum
 * - First Quantile
 * - Median
 * - Third Quantile
 * - Maximum
 * - Number of values
 *
 * @param fout The stream to write to
 * @param statList STL vector of integers (the data set)
 * @param listSum The sum of all the integers in the vector. (Since this is mostly more efficient to calculate while building the vector, it is passed as a parameter. Performance reasons only.)
 *
 * @todo Handle 123-quantiles correct (average odd ones with double precision)
 */
void LoggerCount::writeCountStats(std::fstream &fout, std::vector<int> &statList, int listSum){
	int statCount = statList.size();

	// Check that there are numbers in the list
	if(statCount){
		// Write average size
		fout << "," << ((double)listSum/(double)statCount);

		// Write quantiles
		sort(statList.begin(), statList.end());
		fout << "," << statList[0];

		// TODO: Handle 123-quantiles nice (average odd ones)
		fout << "," << statList[(statCount/2)/2];

		fout << "," << statList[statCount/2];

		fout << "," << statList[statCount/2+((statCount/2)/2)];

		fout << "," << statList[statCount-1];
	}
	// If no numbers are avaliable, output zeroes
	else{
		fout << ",0,0,0,0,0,0";
	}

	// Output number in set
	fout << "," << statCount;
}
